/**
 * 基础菜单 店铺信息
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>店铺管理</el-breadcrumb-item>
    </el-breadcrumb>
     <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search" >
       <el-form-item label="店铺编号">
        <el-input size="small" v-model="formInline.sellerNo" placeholder="输入店铺编号"></el-input>
      </el-form-item>
       <el-form-item label="店铺名称">
        <el-input size="small" v-model="formInline.sellerName" placeholder="输入店铺名称"></el-input>
      </el-form-item>
        <el-form-item size="small" label="店铺类型" prop="serveType">
          <el-select clearable size='small' v-model="formInline.serveType" placeholder="请选择店铺类型" autocomplete="off"
                     style="width: 100%">
            <el-option v-for="(item,index) in dictServeType" :key="index" :label="item.value" :value="item.name">
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-edit"  @click="handleEditYY()">查看店铺营业执照</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column label="" width="65">
        <template scope="scope">
            <el-radio :label="scope.row" v-model="selectRow" @change.native="getTemplateRow(scope.$index,scope.row)"><i></i></el-radio>
        </template>
    </el-table-column>
    <el-table-column sortable prop="sellerNo" label="店铺编号" width="150">
      </el-table-column>
      <el-table-column sortable prop="photo" label="店铺头像"  width="130">
          <!-- 图片的显示 -->
          <template slot-scope="scope">            
            <img :src="scope.row.photo"  width="100" height="50" />
          </template>
      </el-table-column>
      <el-table-column sortable prop="sellerName" label="店铺名称" width="150">
      </el-table-column>
      <el-table-column sortable prop="serveType" label="服务类型" width="100">
      </el-table-column>
      <el-table-column sortable prop="address" label="店铺地址" width="250">
      </el-table-column>
       <el-table-column sortable prop="phoneNum" label="店铺联系方式" width="120">
      </el-table-column>
       <el-table-column sortable prop="creditPoint" label="信用分" width="120">
      </el-table-column>
      <el-table-column sortable prop="remark" label="备注" width="300">
      </el-table-column>
      <el-table-column sortable prop="status" label="店铺状态" width="150">
      </el-table-column>
       <el-table-column sortable prop="registDate" label="注册时间" width="150">
      </el-table-column>
      
      <el-table-column align="center" label="操作" min-width="400">
        <template slot-scope="scope">
          <el-button size="mini" type="success" :disabled="scope.row.status_ori != 0" @click="handleEdit(scope.$index, scope.row)">审核通过</el-button>
          <el-button size="mini" type="danger" :disabled="scope.row.status_ori != 0" @click="deleteUser(scope.$index, scope.row)">审核不通过</el-button>
          <el-button size="mini" type="danger" :disabled="scope.row.status_ori == 2" @click="closeUser(scope.$index, scope.row)">封禁</el-button>
          <el-button size="mini" type="success" :disabled="scope.row.status_ori != 2"  @click="handleEdit(scope.$index, scope.row)">解封</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

     <!-- 营业执照照片上传界面 -->
    <el-dialog :title="title" :visible.sync="editYYPhotoVisible" width="50%" @click="closeYYDialog">
        <!-- <big-img v-if="showImg" @clickit="viewImg"  :imgSrc="imgSrc"></big-img>   -->
       <viewer :images="fileList">
        <ul class="el-upload-list el-upload-list--picture-card" >
         <li tabindex="0" class="el-upload-list__item" v-for="(item,index) in fileList" :key="index">
           <img :src="item.url" alt class="el-upload-list__item-thumbnail">
        </li>
      </ul>
      </viewer>
    </el-dialog>
  </div>
</template>

<script>
import { sellerList, check,dictList,yyPhotoList } from '../../api/sellerMG'
import Pagination from '../../components/Pagination'
import { objectToFormData } from 'object-to-formdata';
import { stringToByte,dataURLtoBlob,base64ToArrayBuffer} from '../../utils/util'


export default {
  data() {
    return {
      imgSrc:'',
      showImg:false,
      selectRow:'',
      sellStatus:0,
      ptype:0,
      limitCount:2,
      showText:'',
      sellerNo:'',
      editYYPhotoVisible:false,
      editFormVisibleYHQ: false,
      serveSelect:'0',
      dictServeType:[],
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      hasSeller:true,
      fileList:[],
      images:[],
      haspic:false,
      dictNameParam:{
        typeNo:3
      },
      editForm: {
        sellerNo:'',
        sellerName:"",
        address:"",
        phoneNum:"",
        remark:"",
        serveType:"0",
        tokenId: localStorage.getItem('tokenId')
      },
      // rules表单验证
      rules: {
        sellerName: [
          { required: true, message: '请输入店铺名', trigger: 'blur' }
        ],
        address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
        phoneNum: [{ required: true, message: '请输入店铺联系方式', trigger: 'blur' }],
        remark: [{ required: true, message: '请输入店铺描述信息', trigger: 'blur' }],
        serveType: [{ required: true, message: '请输入店铺服务类型', trigger: 'blur' }]

      },
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        status:'',
        sellerName:'',
        serveType:'',
        sellerNo:''
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      listDatayhq:[],//优惠券数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },
  mounted(){
  
     dictList(this.dictNameParam)
            .then(res => {
              if (res.code == "1") {
                this.dictServeType = res.data
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    clickImg(e) {
　　　　　　this.showImg = true;
　　　　　　// 获取当前图片地址
　　　　　　this.imgSrc = e.currentTarget.src;
　　　　},
　　　　viewImg(){
　　　　　　this.showImg = false;
　　　　},
    getTemplateRow(index,row){
      this.selectRow = row;
    },
     imageYYChange(file, fileList, name) {//on-change触发
        this.fileList = fileList
      },
      handleYYRmove(file,fileList,name){
        this.fileList = fileList
      },
      imageChange(file, fileList, name) {//on-change触发
        this.fileList = fileList
        this.images.push(fileList[0].raw)
      },
      handleRmove(file,fileList,name){
        this.fileList = []
        this.images = [];
      },
    // 获取公司列表
    getdata(parameter) {
      this.loading = true

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      sellerList(parameter)
        .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            for(let i = 0;i<res.data.datas.length;i++){
              let d = res.data.datas[i]
              res.data.datas[i].address = d.provinceC+d.cityC+d.areaC+d.address;
              res.data.datas[i].photo = 'data:image/png;base64,'+res.data.datas[i].photo;
            }
            this.listData = res.data.datas
            // 分页赋值
            this.pageparm.currentPage = this.formInline.pageIndex
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageIndex = parm.currentPage
      this.formInline.pageSize = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //审核通过
    handleEdit: function(index, row) {
       let param = {
         sellerNo:row.sellerNo,
         status:3
       }
       check(param) .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.getdata(this.formInline);
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('审核失败，请稍后再试！')
        })
    },
    handleEditYY(){
      if(!this.selectRow){
         this.$message({
              type: 'info',
              message: '请选择一条记录!'
            })
          return false;
      }
      this.fileList =[]
      this.editYYPhotoVisible = true
      this.title = '营业执照正反面'
      var param = {
        sellerNo:this.selectRow.sellerNo,
        photoType:0,
        pageIndex:0,
        pageSize:10
      }
      yyPhotoList(param).then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            for(let i = 0;i<res.data.datas.length;i++){
              let bytes = [];
              let obj = new Object();
              let photo = 'data:image/png;base64,'+res.data.datas[i].photo;
              obj.url = photo;
              bytes.push(base64ToArrayBuffer(photo));
              let file = new File(bytes,"photo.png",null)
              obj.raw = file
              this.fileList.push(obj)
            }
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('照片加载失败，请稍后再试！')
        })
    },
    
    // 审核不通过
    deleteUser(index, row) {
      let param = {
         sellerNo:row.sellerNo,
         status:5
       }
       check(param) .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.getdata(this.formInline);
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('审核失败，请稍后再试！')
        })
    },
     // 封禁店铺
    closeUser(index, row) {
     let param = {
         sellerNo:row.sellerNo,
         status:2
       }
       check(param) .then(res => {
          this.loading = false
          if (res.code == "0") {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.getdata(this.formInline);
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('审核失败，请稍后再试！')
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    }
    ,
    closeYYDialog(){
      this.editYYPhotoVisible = false
    },
    closeDialogYHQ(){
      this.editFormVisibleYHQ = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 